package d1_parameter;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;

public class CollectionsTest {
    public static void main(String[] args) {
        List<String> names = new ArrayList<String>();
        names.add("John");
        names.add("Jane");
        names.add("Bob");
        names.add("Jack");
        Collections.addAll(names,new String[]{"John","Jane","Bob"});//批量添加
        System.out.println(names);

        Collections.shuffle(names);//但乱顺序
        System.out.println(names);

        List<Integer> List = new ArrayList<>();
        Collections.addAll(List,new Integer[]{6,2,1,4});
        Collections.sort(List); //排序
        System.out.println(List);
        
        List<Student> students = new ArrayList<>();
        students.add(new Student("大苏打",21,157.1));
        students.add(new Student("的撒",45,188.4));
        students.add(new Student("士大夫",19,167.2));
        students.add(new Student("你好好奋斗",18,177.1));
        Collections.sort(students,new Comparator<Student>() {//sort排序 利用比较器Comparator
            @Override
            public int compare(Student o1, Student o2) {
                return Integer.compare(o1.getAge(),o2.getAge());
            }
        });
    }
}
